<?php
/** @var $model backend\models\Brand */

use backend\models\Brand;
use xj\uploadify\Uploadify;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Html;
//use yii\captcha\Captcha;
use yii\web\JsExpression;

$form =  ActiveForm::begin();
echo $form->field($model,'name');
echo $form->field($model,'logo')->hiddenInput(['id'=>'uploadImg']);
echo Html::img($model->logo,['id'=>'showImg','style'=>'max-height:100px']);
echo Html::fileInput('imginfo', NULL, ['id' => 'test']);
echo Uploadify::widget([
    'url' => yii\helpers\Url::to(['s-upload']),
    'id' => 'test',
    'csrf' => true,
    'renderTag' => false,
    'jsOptions' => [
        'width' => 120,
        'height' => 40,
        'onUploadError' => new JsExpression(<<<EOF
function(file, errorCode, errorMsg, errorString) {
    console.log('The file ' + file.name + ' could not be uploaded: ' + errorString + errorCode + errorMsg);
}
EOF
        ),
        'onUploadSuccess' => new JsExpression(<<<EOF
function(file, data, response) {
    data = JSON.parse(data);
    if (data.error) {
        console.log(data.msg);
    } else {
        //console.log(data.fileUrl);
        //给隐藏域赋值
        $("#uploadImg").val(data.fileUrl);
        //回显图片
        console.dir($("#showImg"));
        
        $("#showImg").attr('src',data.fileUrl);
    }
}
EOF
        ),
    ]
]);

echo $form->field($model,'intro')->textarea();
echo $form->field($model,'sort');
echo $form->field($model,'status',['inline'=>true])->radioList(Brand::$statusInfo);



/*echo $form->field($model,'identifyCode')->widget(yii\captcha\Captcha::className(),[
    'template'=>'<div class="row"><div class="col-lg-3">{input}</div><div class="col-lg-3">{image}</div> </div>',
]);*/



echo Html::submitButton('提交',['class'=>['btn btn-info btn-md']]);
ActiveForm::end();

